﻿using MediatR;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.BasicInformation.Materials;
using THE_WIND_RISES.Common.Domans.Produce.DemandPlanning;
using THE_WIND_RISES.Common.Domans.Produce.ManifestInfos;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.MaterialManagement.Row
{
    public class RowTaskSeachHandler : IRequestHandler<RowTaskSeachCommon, Result>
    {
        private readonly IBaseRepositoryGet<ItemManifestRow> ItemManifestRowRepository;
        private readonly IBaseRepositoryGet<ProductionTasks> ProductionTasksRepository;
        private readonly IBaseRepositoryGet<Choose> ChooseRepository;
        private readonly IBaseRepositoryGet<ItemUnit> ItemUnitRepository;
        private readonly IBaseRepositoryGet<MaterialSpecs> MaterialSpecsRowRepository;

        public RowTaskSeachHandler(IBaseRepositoryGet<ItemManifestRow> itemManifestRowRepository, IBaseRepositoryGet<ProductionTasks> productionTasksRepository, IBaseRepositoryGet<Choose> chooseRepository, IBaseRepositoryGet<ItemUnit> itemUnitRepository, IBaseRepositoryGet<MaterialSpecs> materialSpecsRowRepository)
        {
            ItemManifestRowRepository = itemManifestRowRepository;
            ProductionTasksRepository = productionTasksRepository;
            ChooseRepository = chooseRepository;
            ItemUnitRepository = itemUnitRepository;
            MaterialSpecsRowRepository = materialSpecsRowRepository;
        }

        public async Task<Result> Handle(RowTaskSeachCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };

            //string sql = "SELECT * FROM ItemManifestRow a INNER JOIN ProductionTasks b on a.ChooseId=b.ChooseId Where a.ChooseId="+request.ChooseId;
            string sql = "SELECT * FROM ItemManifestRow Where ChooseId="+request.ChooseId;
            var list = ItemManifestRowRepository.GetAll(sql).ToList();
            if (list != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = list;
                result.Msg = "显示成功";
            }
            else
            {
                result.Msg = "显示失败";
            }
            return result;
        }
    }
}
